package com.youku.plugins.commonui.view
{
   import flash.display.Sprite;
   import com.youku.baseUI.BasePlayerButton;
   import flash.text.TextField;
   import com.youku.utils.AssetUtil;
   import flash.display.MovieClip;
   import com.youku.plugins.commonui.CommonUIConstant;
   import com.youku.plugins.commonui.CommonUIFont;
   import flash.events.MouseEvent;
   import flash.events.TextEvent;
   import com.youku.plugins.commonui.CommonUIEvent;
   import com.youku.utils.DrawUtil;
   
   public class AlertBoxV4 extends Sprite
   {
      
      public function AlertBoxV4() {
         super();
         this.init();
      }
      
      private var _background:Sprite;
      
      private var _closeButton:BasePlayerButton;
      
      private var _confirmButton:BasePlayerButton;
      
      private var _cancleButton:BasePlayerButton;
      
      private var _infoTextField:TextField;
      
      private var _width:Number;
      
      private var _height:Number;
      
      private function init() : void {
         this._background = AssetUtil.getAsset("V4_panel_bg") as MovieClip;
         this._background.width = CommonUIConstant.ALERT_BOX_WIDTH;
         this._background.height = CommonUIConstant.ALERT_BOX_HEIGHT;
         this._closeButton = AssetUtil.getStyleButton("P_CloseButton");
         AssetUtil.restoreButtonSize(this._closeButton);
         this._confirmButton = AssetUtil.getStyleButton("P_Button_OK");
         AssetUtil.restoreButtonSize(this._confirmButton);
         this._confirmButton.hardOffset = -3;
         this._confirmButton.setStyle("textFormat",CommonUIFont.FONT_BUTTON_CONFIRM);
         this._confirmButton.setSize(100,25);
         this._cancleButton = AssetUtil.getStyleButton("P_Button_Cancel");
         AssetUtil.restoreButtonSize(this._cancleButton);
         this._cancleButton.hardOffset = -3;
         this._cancleButton.setStyle("textFormat",CommonUIFont.FONT_BUTTON_CANCLE);
         this._cancleButton.setSize(100,25);
         this._infoTextField = AssetUtil.getTextField(true);
         this._infoTextField.defaultTextFormat = CommonUIFont.FONT_ALEAR_TEXT_NORMAL;
         this._infoTextField.text = "";
         this.addChild(this._background);
         this.addChild(this._infoTextField);
         this.addChild(this._closeButton);
         this.addChild(this._confirmButton);
         this.addChild(this._cancleButton);
         this._closeButton.addEventListener(MouseEvent.CLICK,this.onCancleButtonClick);
         this._cancleButton.addEventListener(MouseEvent.CLICK,this.onCancleButtonClick);
         this._confirmButton.addEventListener(MouseEvent.CLICK,this.onConformButtonClick);
         this._infoTextField.addEventListener(TextEvent.LINK,this.onLinkEvent);
      }
      
      private function onLinkEvent(param1:TextEvent) : void {
         this.dispatchEvent(new CommonUIEvent(CommonUIEvent.ALERT_CONFIRM_CLICK));
      }
      
      private function onConformButtonClick(param1:MouseEvent) : void {
         this.dispatchEvent(new CommonUIEvent(CommonUIEvent.ALERT_CONFIRM_CLICK));
      }
      
      private function onCancleButtonClick(param1:MouseEvent) : void {
         this.dispatchEvent(new CommonUIEvent(CommonUIEvent.ALERT_CANCEL_CLICK));
      }
      
      public function reset(param1:String, param2:String, param3:String) : void {
         this._infoTextField.htmlText = param1;
         this._confirmButton.label = param2;
         this._cancleButton.label = param3;
      }
      
      public function setSize(param1:Number, param2:Number) : void {
         this._width = param1;
         this._height = param2;
         this.updateLayout();
      }
      
      private function updateLayout() : void {
         this._closeButton.x = this._background.x + this._background.width - this._closeButton.width - 10;
         this._closeButton.y = 10;
         var _loc1_:Number = this._confirmButton.width + 16 + this._cancleButton.width;
         this._confirmButton.x = this._background.x + (this._background.width - _loc1_) / 2;
         this._confirmButton.y = this._background.y + this._background.height - this._confirmButton.height - 30;
         this._cancleButton.x = this._confirmButton.x + this._confirmButton.width + 16;
         this._cancleButton.y = this._confirmButton.y;
         this._infoTextField.width = this._width - 50 * 2;
         this._infoTextField.height = this._height - 60 * 2;
         this._infoTextField.x = (this._width - this._infoTextField.width) / 2 + 5;
         this._infoTextField.y = (this._height - this._infoTextField.height) / 2 - 35;
      }
      
      private function getBackGround(param1:Number, param2:Number) : Sprite {
         var _loc3_:Sprite = new Sprite();
         var param1:Number = Math.round(param1);
         var param2:Number = Math.round(param2);
         _loc3_.addChild(DrawUtil.Line(0,0,param1,0,8947848,0.8,1));
         _loc3_.addChild(DrawUtil.Line(param1 - 1,1,param1 - 1,param2 - 1,8947848,0.8,1));
         _loc3_.addChild(DrawUtil.Line(param1,param2 - 1,0,param2 - 1,8947848,0.8,1));
         _loc3_.addChild(DrawUtil.Line(0,1,0,param2 - 1,8947848,0.8,1));
         _loc3_.addChild(DrawUtil.Rectangle(1,1,param1 - 2,param2 - 2,1119254,0.9,null,0));
         return _loc3_;
      }
   }
}
